const image = document.getElementById('image');
let subm = document.querySelector('#subm');

function upload(that) {
	let files = $(that).prop('files');
	image.src = window.URL.createObjectURL(files[0]);
	console.log(files);
}

//异步进行
const predictBreed = async () => {
	console.log("Model is loading...");

	//await,等待<mobilenet>模型装载
	console.time('mobilenet');
	const model = await mobilenet.load();

	//转载完成才执行此句
	console.log("Model loaded Successfully!加载时间:");
	console.timeEnd('mobilenet');

	//等待执行,模型装载后的实例调用它的classify方法
	const predictions = await model.classify(image);
	
	document.querySelector("#dogwhat").innerHTML = '图片中的应该是: <span style="color:red"><a href="https://fanyi.baidu.com/translate?aldtype=16047&query=&keyfrom=baidu&smartresult=dict&lang=auto2zh#auto/zh/">' + predictions[0].className + '<a></span>,契合度:' + Math.round((predictions[0].probability) * 100) + '%';
	
	console.log('The dog in the picture could be: ', predictions);
}


/**
 *生成随机指定长度的字符串
*/
function randomString(len){
	//默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1
	let chars = '0123456789';
	let tempLen = chars.length;let tempStr='';
	for(var i=0; i<len; ++i){
		tempStr += chars.charAt(Math.floor(Math.random() * tempLen ));
	}
	return tempStr;
}